<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
	<title>Group-Buying Meeting Management</title>

	<link rel="stylesheet" type="text/css" href="${ctx}/styles/sidecss.css"/>
	<link rel="stylesheet" type="text/css" href="${ctx}/widgets/extremecomponents/extremecomponents.css"/>
	<link rel="stylesheet" type="text/css" href="${ctx}/scripts/dhtmlxTree/dhtmlxtree.css"/>
	<script type="text/javascript" src="${ctx}/scripts/WinSollAuto.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/base.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/jsUtil.js?webRoot=${ctx}"></script>
	<script type="text/javascript" src="${ctx}/scripts/highchart/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/button.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/zDrag.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/zDialog2.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/dhtmlxTree/dhtmlxtree.js"></script>
	<%@ include file="/commons/meta.jsp" %>
	<!-- jquery dialog -->
	<link rel="stylesheet" href="${ctx}/widgets/jquery/ui/css/jquery-ui.min.css" />
	<script type="text/javascript" src="${ctx}/widgets/jquery/ui/js/jquery-ui.min.js"></script>
	<script type="text/javascript" src="${ctx}/scripts/goods/js/functions.js"></script>

	<link rel="stylesheet" type="text/css" href="${ctx}/widgets/My97DatePicker/skin/WdatePicker.css"/>
	<script type="text/javascript" src="${ctx}/widgets/My97DatePicker/WdatePicker.js"></script>

	<!-- end -->


	<%@ include file="/commons/mdmdialog.jsp"%>
	<script type="text/javascript">
        function query() {
            resetec();
            document.forms[0].action = "${ctx}/crm/crmHdhActivityAction.do?method=hdhActivityList&type=search";
            document.forms[0].submit();
        }
        function selectCity(){
            var form=document.forms[0];
            openDialogList('${ctx}','0','brandSaleArea',form.saleRegionName.value,form.salesArea.value,'',function(v){
                if(v){
                    form.saleRegionName.value=v.text;
                    form.salesArea.value=v.id;
                }
            });
        }
        $(document).ready(function(){
            //用来表识是不是点击搜索按钮进来的，如果是就不清空时间，反之清空时间
            var type = $("#type").val();
            if(!type){
                $(".date_but").each(function(){
                    resetec();
                    $(this).val('');
                })
            }
            $("#checkAll").click(function(){
                if(this.checked){// 全选
                    $("input[type=checkbox]").each(function(){
                        $(this).attr("checked",true);
                    });
                } else {// 取消全选
                    $("input[type=checkbox]").each(function(){
                        $(this).attr("checked", false);
                    });
                }
            });
            //初始化审核不通过弹窗
            $("#auditDialog" ).dialog({
            	autoOpen: false,
            	modal:true,
            	resizable:false,
            	show: {
            	  effect: "blind",
            	  duration: 300
            	},
            	hide: {
            	  effect: "explode",
            	  duration: 300
            	}
            });
        });
        function stopAct() {
            if($(".check:checked").size() != 1){
                alert('Please select an activity to delete');
                return;
            }
           var id = $(".check:checked").val();
            var url =  "${ctx}/crm/crmHdhActivityAction.do?method=stopActivity";
            var choice=confirm("Are you sure you want to delete the activity？", function() { }, null);
            if(choice){
                $.ajax({
                    type:"post",
                    url:url,
                    data:{id:id},
                    success:function(data) {
                        if(data == "success") {
                            alert("Activity deleted successfully!!!");
                            location.href="${ctx}/crm/crmHdhActivityAction.do?method=hdhActivityList";
                        }else{
                            alert("Activity deletion failed!!!");
                        }
                    },
                    error:function () {
                        alert("Close the failure");
                    }
                })
            }
        }
        //活动延期
        function postponeHdhActivity(actId,startTime,endTime){
            $("#actId").val(actId);
            $("#startTime").val(startTime);
            $("#endTime").val(endTime);
            var url="${ctx}/crm/crmHdhActivityAction.do?method=postponeHdhActivity";
            $("#dialog-input").dialog({
                resizable : false,
                height : "300",
                title : "Set the end time of the activity",
                width : 820,
                modal : true,
                buttons : {
                    "取消" : function() {
                        $(this).dialog("close");
                    },
                    "提交":function(){
                        var endTime=$("#endTime").val();
                        $.ajax({
                            type:"post",
                            url:url,
                            data:{actId:actId,endTime:endTime},
                            success:function(data)
                            {
                                if(data == "success")
                                {
                                    alert("modify successfully!!!");
                                    $("#dialog-input").dialog("close");
                                    location.href="${ctx}/crm/crmHdhActivityAction.do?method=hdhActivityList";
                                }else{
                                    alert("fail to modify!!!");
                                }
                            },
							error:function () {
                                alert("fail to modify!!!");
                            }
                        })
                    }
                }
            });
        }
        
        //经销商名称查询
        function selectPoi() {
            var form = document.forms[0];
            var userId = $("#isAreaUser").val();
            var jsonParam = {};
            if (userId != "") {
                jsonParam.userId = userId;
                openDialogList('${ctx}', '0', 'poiAreaDealerList', form.dealerName.value, form.dealerId.value, '', function (v) {
                    if (v) {
                        form.dealerId.value = v.id;
                        form.dealerName.value = v.text;
                    }
                }, '', jsonParam);
            } else {
                openDialogList('${ctx}', '0', 'poiDealerList', form.dealerName.value, form.dealerId.value, '', function (v) {
                    if (v) {
                        form.dealerId.value = v.id;
                        form.dealerName.value = v.text;
                    }
                });
            }
        }

        //审核活动
        function auditActivity(id,status){
            var url="${ctx}/crm/crmHdhActivityAction.do?method=auditActivity";
            $.ajax({
                type:"post",
                url:url,
                data:{id:id,status:status},
                success:function(data) {
                    if(data == "success") {
                        alert("Activity audit successful!!!");
                        location.href="${ctx}/crm/crmHdhActivityAction.do?method=hdhActivityList";
                    }else{
                        alert("Activity audit failed!!!");
                    }
                },
                error:function () {
                    alert("Close the failure");
                }
            })

        }
        //审核不通过弹窗
        function auditNoPassWindow(id){
        	$("#hiddenActId").val(id);
        	$('#auditDialog').dialog('open');
        }
        //审核不通过
        function auditNoPass(id){
        	$.post('${ctx}/crm/crmHdhActivityAction.do?method=auditActivity',{id:id,status:'2',reason:$('#reason').val()},function(data){
        		if(data == "success") {
                    alert("Activity audit successful!!!");
                    query();
                }else{
                    alert("Activity audit failed!!!");
                }
        		//关闭
        		$('#auditDialog').dialog('close');
        	});
        }
        //复制活动
		function copyActivity(id){
        	if(confirm('Are you sure you want to copy the activity?')){
        		loading();
				$.post('${ctx}/crm/crmHdhActivityAction.do?method=copyActivity',{id:id},function(data){
					if(data&&data=='1'){
						alert('Replication activity successful！');
						query();
					}else{
						alert('Copy the failure：'+data);
						unloading();
					}
				});
        	}
		}
        //销售区域
        function selectSaleArea() {
            var form = document.forms[0];
            var userId = $("#isAreaUser").val();
            var jsonParam = {};
            if (userId != "") {
                jsonParam.userId = userId;
                openDialogList('${ctx}', '0', 'hdhAreaSaleArea', '', '', '', function (v) {
                    if (v) {
                        form.areaId.value = v.id;
                        form.areaName.value = v.text;
                    }
                }, '', jsonParam);
            } else {
                openDialogList('${ctx}', '0', 'hdhSaleArea', '', '', '', function (v) {
                    if (v) {
                        form.areaId.value = v.id;
                        form.areaName.value = v.text;
                    }
                });
            }
        }
	</script>
	<style>
		.MenuList a.cancel{width:58px;background: url(../images/MenuBut1_03.gif) no-repeat;}
		.MenuList a.cancel:hover{background: url(../images/MenuBut1_05.gif) no-repeat;}
	</style>
</head>

<body onLoad="WindowSollAuto()" onResize="WindowSollAuto()">
<jsp:include page="/commons/messages.jsp" flush="true"></jsp:include>
<html:form action="/crm/crmHdhActivityAction.do?method=hdhActivityList" method="post" >

<div class="bosom_one">
	<div class="bosom_top">
		<span class="left"></span>
		<h4>Group-Buying Meeting List</h4>
		<div class='MenuList'>
			<!-- add -->
			<a href="javascript:query();" >query</a>
			<a href="javascript:window.location.href='${ctx}/crm/crmHdhActivityAction.do?method=toSaveHdhActivity'" >Add</a>
			<c:if test="${empty isAreaUser}">
				<a href="javascript:stopAct();">Delete</a>
			</c:if>
		</div>
		<span class="right"></span>
	</div>

	<div class="bosom_side">
		<div class="casing">
			<div class="caput">
				<span class="left"></span><span class="right"></span>
			</div>
			<div class="viscera" id="SollAuto">
				<div class="sheet_div">
					<div class="searchbox" id="searchbox">
						<table>
							<html:hidden property="isAreaUser" styleId="isAreaUser" value="${isAreaUser}" />
							<tr>
								<td>Activity ID：<html:text name="ec" property="id" styleId="id" onkeyup="value=value.replace(/[^\d]/g,'')" onkeydown="value=value.replace(/[^\d]/g,'')" onchange="value=value.replace(/[^\d]/g,'')"/></td>
								<td>Activity Name：<html:text name="ec" property="name" styleId="name"/></td>
								<td>Review Status：
									<html:select name="ec" property="audit">
										<html:option value="">All</html:option>
										<html:option value="0">Not audit</html:option>
										<html:option value="1">pass the audit</html:option>
										<html:option value="2">Refuse to review</html:option>
									</html:select>
								</td>
								<td>Sales Area： <html:text name="ec" property="areaName"
													 styleId="areaName" styleClass="select_but"
													 onclick="selectSaleArea()" readonly="true" /> <html:hidden
										property="areaId" styleId="areaId" />
								</td>
								<td>Province：<html:text name="ec" property="provinceName" styleId="provinceName"/></td>
								<td>City：<html:text name="ec" property="cityName" styleId="cityName"/></td>
								<td>Region：<html:text name="ec" property="county" styleId="county"/></td>
								<td>Group-Buying Meeting Type：
									<html:select name="ec" property="activityType">
										<html:option value="">All</html:option>
										<html:option value="1">Retail</html:option>
										<html:option value="2">Wholesale</html:option>
									</html:select>
								</td>
								<td>Whether an Offline Rebate：
									<html:select name="ec" property="activityOfflineRebate">
										<html:option value="">All</html:option>
										<html:option value="1">Yes</html:option>
										<html:option value="2">No</html:option>
									</html:select>
								</td>
								<td>Distributor Name：
								<%-- <html:text name="ec" property="dealerName" styleId="dealerName"/> --%>
								<html:text name="ec" property="dealerName" styleId="dealerName" styleClass="select_but" onclick="selectPoi()" readonly="true"  />
								<html:hidden property="$eq_dealerId" styleId="dealerId"  />
								</td>
								<td>Activity Start Time</td>
								<td>
									<html:text property="startTime" styleId="startTime" onclick="WdatePicker({maxDate:'#F{$dp.$D(\\'endTime\\')}',dateFmt:'yyyy-MM-dd HH:mm:ss','lang':'en'});" readonly="true" styleClass="date_but" style="width: 150px"></html:text>
									<input type="hidden" value="${param.type}" id="type"/>
								</td>
								<td>Activity End Time</td>
								<td>
									<html:text property="endTime" styleId="endTime" onclick="WdatePicker({minDate:'#F{$dp.$D(\\'startTime\\')}',dateFmt:'yyyy-MM-dd HH:mm:ss','lang':'en'});" readonly="true" styleClass="date_but" style="width: 150px"></html:text>
								</td>
							</tr>
						</table>
					</div>
					<ec:table items="list" var="item" onInvokeAction="query();"
							  form="hdhActivityForm" retrieveRowsCallback="limit"
							  style="width:100%" tableId="ec" locale = "en_US"
							  action="${ctx}/crm/crmHdhActivityAction.do?method=hdhActivityList&grp=winretailsaler">
                        <ec:exportXls fileName="Group-Buying Meeting Info.xls" tooltip="Export Excel" view="xls" />
						<ec:exportCsv fileName="Group-Buying Meeting Info.csv" tooltip="Export CVS']}" view="csv" />
						<ec:row highlightRow="true">
							<ec:column width="30" title="<input type='checkbox' id='checkAll'/>" property="id" sortable="false" viewsDenied="xls,csv">
								<input type="checkbox" name="check" class="check" value="${item.id}"/>
							</ec:column>
							<ec:column property="ROWCOUNT" title="No." ><center>${ROWCOUNT}</center></ec:column>
							<ec:column property="opt" width="1%" title="operation" sortable="false" viewsDenied="xls,csv">
								<html:link page="/crm/crmHdhActivityAction.do?method=viewHdhActivity&id=${item.id}">
									<img src="${ctx}/images/view.gif" border="0" alt="view'" title="view" />
								</html:link>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<c:if test="${empty isAreaUser}">
									<html:link
											page="/crm/crmHdhActivityAction.do?method=toUpdateHdhActivity&id=${item.id}"
											target="main">
										<img src="${ctx}/images/edit.gif" border="0" alt="edit"
											 title='edit'/>
									</html:link>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%-- 									<a href="javascript:postponeHdhActivity('${item.id}','${item.startTime}','${item.endTime}')">延期</a>&nbsp;&nbsp; --%>
									<c:if test="${item.audit == 0}">
										<a href="javascript:auditActivity('${item.id}','1')">pass the audit</a>&nbsp;&nbsp;
										<a href="javascript:auditNoPassWindow('${item.id}')">Refuse to review</a>&nbsp;&nbsp;
									</c:if>
									<c:if test="${item.audit eq 1}">
										<a href="javascript:copyActivity('${item.id}')">Copy the activity</a>&nbsp;&nbsp;
									</c:if>
								</c:if>
							</ec:column>
                            <ec:column property="activityId" title="Activity ID" value="${item.id}" />
							<ec:column property="name" title="Activity Name" />
							<ec:column property="dealerName" title="Distributor Name" />
							<ec:column property="areaName" title="Sales Area"/>
							<ec:column property="provinceName" title="Province"/>
							<ec:column property="cityName" title="City"/>
							<ec:column property="countyName" title="Region"/>
							<ec:column property="activityType" title="Group-Buying Meeting Type"><c:if test="${item.activityType eq '1'}">Retail</c:if><c:if test="${item.activityType eq '2'}">Wholesale</c:if></ec:column>
							<ec:column property="activityOfflineRebate" title="Group-Buying Meeting Type"><c:if test="${item.activityOfflineRebate eq '1'}">yes</c:if><c:if test="${item.activityOfflineRebate eq '2'}">no</c:if></ec:column>
							<ec:column property="bannerImg" title="Activity Photos"  viewsDenied="xls,csv"><center><html:link href="${item.bannerImg}" target="_blank" style="color:#FF0000;"><img src="${item.bannerImg}" width="40" height="40" border="0" onerror="javascript:this.src='/images/close.png';" /></html:link></center></ec:column>

							<ec:column property="activityImg" title="Explanatory picture of Hui Order"  viewsDenied="xls,csv"><center><html:link href="${item.activityImg}" target="_blank" style="color:#FF0000;"><img src="${item.activityImg}" width="40" height="40" border="0" onerror="javascript:this.src='/images/close.png';" /></html:link></center></ec:column>
							<ec:column property="extendVideo" title="Promotion Video"  viewsDenied="xls,csv"><center><html:link href="${item.extendVideo}" target="_blank">${item.extendVideo}</html:link></ec:column>
							<ec:column property="videoFileId" title="Tencent Cloud video Id"/>
							<ec:column property="hdhRate" title="Rate (%)"/>
							<ec:column property="activeStoreQty" title="Total Active Customers"/>
							<ec:column property="GVM" title="GMV"/>
							<ec:column property="callBackProfits" title="Rebate (%)"/>
							<ec:column property="activityRuleType" title="Group-Buying Meeting Type"><c:if test="${item.activityRuleType eq '1'}">Make a reduction and give a fulfil-quota gift according to the amount</c:if><c:if test="${item.activityRuleType eq '2'}">Double the reduction and fulfil-quota gift according to the amount</c:if><c:if test="${item.activityRuleType eq '3'}">Double the reduction and fulfil-quota gift according to number of pieces</c:if></ec:column>
							<ec:column property="startTime" title="Activity Start Time"/>
							<ec:column property="endTime" title="Activity End Time"/>
							<ec:column property="createdBy" title="Creator"/>
							<ec:column format="yyyy-MM-dd HH:mm:ss" cell="date" property="created" title="Creation time" />
							<ec:column property="updatedBy" title="Updated by"/>
							<ec:column format="yyyy-MM-dd HH:mm:ss" cell="date" property="updated" title="Update time" />
							<ec:column property="audit" title="Review Status"><c:if test="${item.audit eq '0'}">Not audit</c:if><c:if test="${item.audit eq '1'}">pass the audit</c:if><c:if test="${item.audit eq '2'}">Refuse to review</c:if></ec:column>
							<ec:column property="auditBy" title="Reviewer"/>
							<ec:column format="yyyy-MM-dd HH:mm:ss" cell="date" property="auditTime" title="Review Time" />
						</ec:row>
					</ec:table>
				</div>
				<div id="dialog-input" style="display: none">
					<div class="window">
						<div class="windowInfo">
							<tr>
								<td class="formTable" width="1%"><font color="#FF0000">*</font>Activity end date：</td>
								<td align="left" width="1%">
									<input type="hidden" id="actId" />
									<input type="hidden" id="startTime" name="startTime" class="Wdate" type="text" readonly="true" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'endTime\')||\'2020-10-01\'}',dateFmt:'yyyy-MM-dd HH:mm:ss','lang':'en'})" /><label style="color:#FF0000"></label>
									<input id="endTime" name="endTime" class="Wdate" type="text" readonly="true" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'startTime\')}',maxDate:'2020-10-01',dateFmt:'yyyy-MM-dd HH:mm:ss','lang':'en'})" /><label style="color:#FF0000"></label>
								</td>
							</tr>
						</div>
					</div>
				</div>
				<div class="trail">
					<span class="fleft"></span><span class="fright"></span>
				</div>
			</div>
		</div>
		<div class="bosom_bottom">
			<span class="left"></span><span class="right"></span>
		</div>
	</div>
	</html:form>
	<!-- 弹框 -->
	<div id="auditDialog" style="display:none;" title="Refusal cause">
		<input type="hidden" id="hiddenActId"/>
		<div style="text-align: center;margin-bottom:5px;"><textarea rows="5" id="reason" cols="35" maxLength="100" title="Less than 100 words"></textarea></div>
		<div style="text-align: center">
			<input type="button" value="confirm" onclick="auditNoPass($('#hiddenActId').val())">&nbsp;&nbsp;&nbsp;<input type="button" value="cancel" onclick="$('#auditDialog').dialog('close');">
		</div>
	</div>
</body>
</html>